package com.sqx.modules.health.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.modules.health.common.Result;
import com.sqx.modules.health.entity.AppUpgrade;
import com.sqx.modules.health.service.IAppUpgradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 患者康复方案记录表 前端控制器
 * </p>
 *
 * @author hsx
 * @since 2022-09-13
 */
@Slf4j
@Api(value = "患者康复方案记录表", tags = "", description = "")
@RestController
@RequestMapping("/health/app/app_upgrade")
public class HealthAppUpgradeController {
    @Autowired
    private IAppUpgradeService appUpgradeService;

    @GetMapping("/update")
    @ApiOperation(value = "app更新信息", notes = "app更新信息")
    public Result update(@RequestParam String appid,@RequestParam String version){
        Map<String, Object> res = new HashMap<>();
        res.put("status", 0);
        QueryWrapper<AppUpgrade> wrapper = new QueryWrapper<>();
        wrapper.eq("appid", appid).orderByDesc("id");
        List<AppUpgrade> list = appUpgradeService.list(wrapper);
        if (list.size() > 0) {
            AppUpgrade appUpgrade = list.get(0);
            if (!appUpgrade.getVersion().equals(version)) {
                res.put("message", appUpgrade.getMessage());
                res.put("isforce", appUpgrade.getIsforce());
                res.put("url", appUpgrade.getUrl());
                res.put("version", appUpgrade.getVersion());
                res.put("status", 1);
            }
        }
        return Result.success(res);
    }

}

